﻿using System;
using System.Collections.Generic;

using System.Text;

namespace HZ.DrugTrade.DAL
{
    public class DAL_AdjustPricePlan
    {
        public static int ExecuteAdjustPrice(HZ.DrugTrade.Model.AdjustPricePlan plan)
        {
            try
            {
                string sql = string.Format(@"UPDATE TB_ProcureCatalog SET ProcurePrice = {0} WHERE ProcureCatalogID = '{1}'
UPDATE TB_AdjustPricePlan SET ExecuteState = 1 WHERE ProcureCatalogID = '{1}'", plan.AdjustPrice, plan.ProcureCatalogID);
                HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(sql);

                sql = string.Format(@"UPDATE TB_HospitalProcureCatalog
   SET Price = {0},SellPrice = {1} WHERE ProcureCatalogID = '{2}' ", plan.AdjustPrice, (plan.AdjustPrice ?? 0) * decimal.Parse("1.15"), plan.ProcureCatalogID);

                HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(sql);

                Model.AdjustPriceLog log = new HZ.DrugTrade.Model.AdjustPriceLog() { PriceLogSerialID = Guid.NewGuid().ToString(), AdjustPrice = plan.AdjustPrice, AdjustPricePerson = plan.PlanPerson, AdjustPriceReason = plan.AdjustPriceReason, AdjustPriceTime = DateTime.Now, OriginalPrice = plan.OriginalPrice, ProcureCatalogID = plan.ProcureCatalogID };

                HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(HZ.Data.DAL_Helper.GetInsertSql(log));
                return 1;
            }
            catch (Exception ee)
            {
                return 0;

            }


        }
    }
}
